package com.curry.android.base;



import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;

import android.support.v4.app.FragmentActivity;

import android.view.View;

import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import com.curry.android.callback.ICallBack;


@Deprecated
public class BaseFragmentActivity extends FragmentActivity implements ICallBack{
	public static final String TAG = "BaseActivity";
	private ProgressDialog progressDialog;
	/** 定义成全局的便于关闭界面时，清除注册的广播 */
	private ExitListenerReceiver exitre = null;
	protected SharedPreferences mPreferences;
	/** 是否开启全屏 */
	private boolean isFullScreen = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	/** 设置键盘不显示 */
	protected void hideSoftInput() {
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
	}

	/** 是否开启全屏 */
	protected void setFullScreen(boolean isFullScreen) {
		this.isFullScreen = isFullScreen;
	}

	public void onBackClick(View v) {
 		finish();
 	 }
	
	/** 开启全屏 */
	protected void openFullScreen() {
		if (isFullScreen) {
			requestWindowFeature(Window.FEATURE_NO_TITLE);
			requestWindowFeature(Window.FEATURE_PROGRESS);
		}
	}

	/**
	 * 注册退出事件监听
	 */
	public void RegListener() {
		exitre = new ExitListenerReceiver();
		IntentFilter intentfilter = new IntentFilter();
		intentfilter.addAction(this.getPackageName() + "."
				+ "ExitListenerReceiver");
		this.registerReceiver(exitre, intentfilter);
	}

	class ExitListenerReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context arg0, Intent arg1) {
			((Activity) arg0).finish();
		}
	}

	protected void openProgressDialog(String title, String message) {
		closeProgressDialog();
		progressDialog = new ProgressDialog(this);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progressDialog.setTitle(title);
		progressDialog.setMessage(message);
		progressDialog.show();
	}

	protected void closeProgressDialog() {
		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.cancel();
			progressDialog.dismiss();
			progressDialog = null;
		}
	}

	// @Override
	// public boolean dispatchKeyEvent(KeyEvent event) {
	// if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
	// InputMethodManager imm = (InputMethodManager)
	// getSystemService(BaseActivity.INPUT_METHOD_SERVICE);
	// // 得到InputMethodManager的实例
	// if (imm.isActive()) {
	// // 如果开启
	// imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
	// InputMethodManager.HIDE_NOT_ALWAYS);
	// // 关闭软键盘，开启方法相同，这个方法是切换开启与关闭状态的
	// }
	// return super.dispatchKeyEvent(event);
	// }
	// return super.dispatchKeyEvent(event);
	// }

	@Override
	public void request(String buf, Handler handler, int wat) throws Exception {

	}
	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            if (isFastDoubleClick()) {
                return true;
            }
        }
        return super.dispatchTouchEvent(ev);
	}
	long lastClickTime=0;
	public  boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (timeD >= 0 && timeD <= 1000) {
            return true;
        } else {
            lastClickTime = time;
            return false;
        }
    }
}
